package com.example.liang.basamovie.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.liang.basamovie.R;
import com.example.liang.basamovie.bean.FindFilmCasts;
import com.example.liang.basamovie.utils.ImageLoaderUtils;

import java.util.List;

/**
 * 演员横向滑动的适配器
 */
public class FindFilmPlayerApater extends RecyclerView.Adapter<FindFilmPlayerApater.MyViewHolder>{
    List<FindFilmCasts> list;
    Context context;

    public FindFilmPlayerApater(List<FindFilmCasts> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_find_filmplayerinfo_layout, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        FindFilmCasts casts = list.get(position);
        holder.playerName.setText(casts.getName());
        ImageLoaderUtils.getimage(context,casts.getImage_url(),holder.playerImage);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView playerName;
        ImageView playerImage;
        public MyViewHolder(View itemView) {
            super(itemView);
            playerName= (TextView) itemView.findViewById(R.id.find_playerName);
            playerImage= (ImageView) itemView.findViewById(R.id.find_playerImage);
        }
    }
}
